package gold.digger;

import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC284 {
    public long startExecuteTime = System.currentTimeMillis();


    class PeekingIterator implements Iterator<Integer> {
        Deque<Integer> deque;

        public PeekingIterator(Iterator<Integer> iterator) {
            // initialize any member here.
            deque = new LinkedList<>();
            while (iterator.hasNext()) {
                deque.offerLast(iterator.next());
            }
        }

        // Returns the next element in the iteration without advancing the iterator.
        public Integer peek() {
            return deque.peekFirst();
        }

        // hasNext() and next() should behave the same as in the Iterator interface.
        // Override them if needed.
        @Override
        public Integer next() {
            return deque.pollFirst();
        }

        @Override
        public boolean hasNext() {
            return deque.size() > 0;
        }
    }

    public void run() {
        PeekingIterator solution = new PeekingIterator(null);
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC284 an = new LC284();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
